﻿<!DOCTYPE html>

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>工序人员配置</title>
    <meta name="renderer" content=padding>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/js/layui/css/layui.css" rel="stylesheet" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
</head>
<body>
    <ul lay-bar="disabled" class="mWebBanner">
        <li class="layui-nav-item" style="float:left;">
            <button id="btn-update" type="button" name="btn_update" onclick="Confirm()" class="buttonCss">
                <i class="layui-icon" style="margin-right:3px">&#x1005;</i>确认选择
            </button>
        </li>


        <li class="layui-nav-item" style="float:left;margin-left:3%">
            <button id="btn-sync" type="button" onclick="closeWin()" class="buttonCss">
                <i class="layui-icon" style="margin-right:3px">&#x1007;</i> 关闭页面
            </button>
        </li>
    </ul>
    <div class="layui-fluid" style="width:100%;">

        <div style="float:left;width:100%;">
            <div class="layui-card">

                <div class="layui-card-body layui-table-body" id="layui-table-main">
                    <table class="layui-hide" id="list" lay-filter="list"></table>
                </div>
            </div>


        </div>
    </div>
</body>
</html>
<script src="~/js/framework/sysframework.js"></script>
<script src="~/js/framework/commonjs.js"></script>
<script type="text/html" id="barDemo">
    <a title="删除" href="javascript:;" lay-event="del" id="frmDel"><i class="layui-icon">&#xe640;</i></a>
</script>
<script>
    var gxCode = "";
    var cData = undefined;
    $(function () {
        gxCode = getUrlVariable("gxCode");
        loadData();
    })

    var dUrl = "../ProductSet/getDataList?dataType=gxus&condition=";
    /**
     * 加载数据
     * **/
    function loadData() {
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#list'
                , cols: [[ //标题栏
                    { type: 'checkbox' }
                    , { field: 'userCode', align: 'center', title: '登录账号', width: 120 }
                    , { field: 'userName', align: 'center', title: '人员名称', width: 170 }
                    , { field: 'right', align: 'center', title: '数据操作', toolbar: '#barDemo', width: 120, fixed: 'right' }
                ]], done: function (res, curr, count) {
                    // $("[data-field='id']").css('display', 'none');//隐藏列
                    currPage = curr;
                    $.each(res['data'], function (i, j) {
                        if (j['gx'] == "1") {
                            TableRowColor('layui-table-main', i, '#C3FDB8');
                        }
                    });
                }
                , url: dUrl + gxCode
                , skin: 'row' //表格风格
                , even: true
                , page: true //是否显示分页
                , limits: [15, 25, 30]
                , limit: 15//每页默认显示的数量
                , id: "list"
            });
            //监听工具条
            table.on('tool(list)', function (obj) {
                var data = obj.data;
                if (obj.event != 'yflzy' && data.status == "ps-doing") {
                    layer.msg('计划已派工，禁止操作'); return;
                }
                if (obj.event == 'del') {
                    layer.confirm('确认要删除该数据？', function (index) {
                        $.ajax({
                            url: "../ProductSet/DelGongXuUser",
                            type: "post",
                            data: { gxCode: gxCode,userCode:data.userCode },
                            success: function (data) {
                                if (data.result) {
                                    layer.msg("删除成功");
                                    obj.del();
                                } else {
                                    layer.msg(data.message);
                                }
                                loadData();
                            }
                        });
                        layer.close(index);
                    });
                }
             

            });
            table.on('checkbox(list)', function (obj) {
                var checkStatus = table.checkStatus('list');
                var select = new Array();
                for (var i = 0; i < checkStatus.data.length; i++) {
                    if (checkStatus.data[i].gx == "1") {
                        layer.msg("此人员不能选择：" + checkStatus.data[i].userName);
                        cData = "";
                        return;
                    }
                    select += checkStatus.data[i].userCode + ",";
                }
                cData = select.slice(0, -1);
            });

        });

    }


    function Confirm() {
        var users = cData;
        if (cData = "") {
            layer.msg("您没有选择任何数据"); return;
        }
        $.ajax({
            url: "../ProductSet/AddGongXuUser",
            type: "post",
            data: { userCodes: users, gxCode: gxCode },
            success: function (data) {
                if (data.result) {
                    layer.msg("数据保存成功");
                    loadData();
                } else {
                    layer.msg(data.message);
                }
            }
        });
    }

</script>
